//
//  CommonQuestionsHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/4/2.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "CommonQuestionsHeaderView.h"


@interface CommonQuestionsHeaderView ()

/**
 questionsData
 */
@property (nonatomic , strong) NSArray *questionsData;

@end

@implementation CommonQuestionsHeaderView

#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.questionsData = @[@{@"title" : @"领养问题", @"icon" : @"system_questions_lingyang"},
                               @{@"title" : @"豚券问题", @"icon" : @"system_questions_tunquan"},
                               @{@"title" : @"提现问题", @"icon" : @"system_questions_tixian"},
                               @{@"title" : @"申诉问题", @"icon" : @"system_questions_shensu"},
                               @{@"title" : @"会员问题", @"icon" : @"system_questions_huiyuan"},
                               @{@"title" : @"账号问题", @"icon" : @"system_questions_zhanghao"},
                               @{@"title" : @"分割问题", @"icon" : @"system_questions_fenge"},
                               @{@"title" : @"其他问题", @"icon" : @"system_questions_qita"}];
        
        
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self initStatusBtn];
}

- (void)initLayout {
    // 布局子控件
 
}
- (void)initStatusBtn {
    CGFloat btnWH = 60;
    CGFloat margin = (SCREEN_WIDTH - btnWH * 4)/5;
    CGFloat lineSpacing = 5;
    NSInteger tempIndex = 0;
    NSInteger tempLineCount = 0;
    for (int i = 0; i < 8; i++) {
        tempIndex = i%4;
        if (i >= 4) {
            tempLineCount = 1;
        }
        NSDictionary *dic = self.questionsData[i];
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:dic[@"icon"]]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = dic[@"title"];
        titleLabel.font = [UIFont smallFont];
        titleLabel.textColor = [UIColor colorWithHexString:@"#262626"];
    
        HButtonView *btn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
        [self addSubview:btn];
        [self.questionTypeBtnArray addObject:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(margin * (tempIndex + 1) + btnWH * tempIndex);
            make.top.mas_equalTo(4 * lineSpacing + (lineSpacing + btnWH) * tempLineCount);
            make.size.mas_equalTo(CGSizeMake(btnWH, btnWH));
        }];
    }
}

#pragma mark - getter and setter

- (NSMutableArray<HButtonView *> *)questionTypeBtnArray {
    if (!_questionTypeBtnArray) {
        _questionTypeBtnArray = [NSMutableArray array];
    }
    return _questionTypeBtnArray;
}
- (NSArray *)questionsData {
    if (!_questionsData) {
        _questionsData = [NSArray array];
    }
    return _questionsData;
}

@end
